
/*
'===============================================================================
'  Generated From - BLL_Component_Partial_Core.vbgen
'  
'  This object is partial class component representing a table in a database. It
'  contains core data access methods. Other partial classes should be used for 
'  implementing custom business logic. This class can be regenerated many times.
'  
'  Do not write custom business logic in this class as it will be overwritten 
'  next time the class is generated.
'
'  Version: 1.0
'  Date:	30/01/06
'  Summary: SelectOne, SelectAll, SelectAllWForeignKey, Insert, Update, Delete,
'  			DeleteAllWForeignKey, class for sorting.
'===============================================================================
*/
using System;
using System.Data;
using System.Collections.Generic;

namespace PlacementManager
{
    public partial class ContactDetailComponent
    {
        
		/// <summary>
        /// Default constructor.
        /// </summary>
		public ContactDetailComponent()
        {

        }
		
		/// <summary>
        /// Selects one record from the database table using the primary key.
        /// </summary>
        /// <returns>An object of a type representing a row in the database table.</returns>
		public ContactDetail SelectOne(int ContactDetailId)
        {  
			PlacementManager.DAL.ContactDetail_DAL o = new PlacementManager.DAL.ContactDetail_DAL();
			o.ContactDetailId = ContactDetailId;
			DataTable dt = o.SelectOne().Tables[0];
			
			if (dt.Rows.Count > 0)
            {
                DataRow row = dt.Rows[0];
				PlacementManager.ContactDetail ContactDetailToReturn = new PlacementManager.ContactDetail((int)row["ContactDetailId"], (int)row["UserId"], (int)row["CategoryDetailId"], (bool)row["IsPrimary"], (bool)row["IsActive"], (string)row["Note"], (DateTime)row["DateCreated"], (string)row["CreatedBy"], (DateTime)row["DateUpdated"], (string)row["UpdatedBy"]);
				return ContactDetailToReturn;
			}
			else
			{
				PlacementManager.ContactDetail ContactDetailToReturnEmpty = new PlacementManager.ContactDetail();
                return ContactDetailToReturnEmpty;
			}
        }
		
		/// <summary>
        /// Selects all records from the database table.
        /// </summary>
        /// <returns>A collection of objects of a type representing a row in the database table.</returns>
		public List<ContactDetail> SelectAll(string sortExpression)
        {
            List<ContactDetail> listContactDetail = new List<ContactDetail>();
            PlacementManager.DAL.ContactDetail_DAL o = new PlacementManager.DAL.ContactDetail_DAL();

            DataSet ds = o.SelectAll();

            foreach (DataRow row in ds.Tables[0].Rows)
            {
                listContactDetail.Add(new ContactDetail((int)row["ContactDetailId"], (int)row["UserId"], (int)row["CategoryDetailId"], (bool)row["IsPrimary"], (bool)row["IsActive"], (string)row["Note"], (DateTime)row["DateCreated"], (string)row["CreatedBy"], (DateTime)row["DateUpdated"], (string)row["UpdatedBy"]));
            }

            listContactDetail.Sort(new ContactDetailComparer(sortExpression));
            return listContactDetail;
        }
	
		/// <summary>
        /// Selects all records from the database table based on a foreign key.
        /// </summary>
        /// <returns>A collection of objects of a type representing a row in the database table.</returns>


		/// <summary>
        /// Inserts a new row into the datatable.
        /// </summary>
        /// <param name="o">An object of a datatype representing a row in the database table.</param>
        /// <returns>Boolean</returns>
		public int Insert(ContactDetail o)
        {	
            PlacementManager.DAL.ContactDetail_DAL oContactDetail = new PlacementManager.DAL.ContactDetail_DAL();
			oContactDetail.UserId = o.UserId;
			oContactDetail.CategoryDetailId = o.CategoryDetailId;
			oContactDetail.IsPrimary = o.IsPrimary;
			oContactDetail.IsActive = o.IsActive;
			oContactDetail.Note = o.Note;
			oContactDetail.DateCreated = o.DateCreated;
			oContactDetail.CreatedBy = o.CreatedBy;
			oContactDetail.DateUpdated = o.DateUpdated;
			oContactDetail.UpdatedBy = o.UpdatedBy;

            return oContactDetail.Insert();
        }
		
		/// <summary>
        /// Inserts a new row into the datatable by passing parameters represneting each column.
        /// </summary>
        /// <returns>Boolean</returns>
		public int Insert(int UserId, int CategoryDetailId, bool IsPrimary, bool IsActive, string Note, DateTime DateCreated, string CreatedBy, DateTime DateUpdated, string UpdatedBy)
        {
            PlacementManager.DAL.ContactDetail_DAL oContactDetail = new PlacementManager.DAL.ContactDetail_DAL();

			oContactDetail.UserId = UserId;
			oContactDetail.CategoryDetailId = CategoryDetailId;
			oContactDetail.IsPrimary = IsPrimary;
			oContactDetail.IsActive = IsActive;
			oContactDetail.Note = Note;
			oContactDetail.DateCreated = DateCreated;
			oContactDetail.CreatedBy = CreatedBy;
			oContactDetail.DateUpdated = DateUpdated;
			oContactDetail.UpdatedBy = UpdatedBy;

            return oContactDetail.Insert();
        }

		/// <summary>
        /// Updates a row in the database table based on the primary key.
        /// </summary>
        /// <param name="o">An object of a datatype representing a row in the database table.</param>
        /// <returns>Boolean</returns>
		public bool Update(ContactDetail o)
        {	
            PlacementManager.DAL.ContactDetail_DAL oContactDetail = new PlacementManager.DAL.ContactDetail_DAL();
			oContactDetail.ContactDetailId = o.ContactDetailId;
			oContactDetail.UserId = o.UserId;
			oContactDetail.CategoryDetailId = o.CategoryDetailId;
			oContactDetail.IsPrimary = o.IsPrimary;
			oContactDetail.IsActive = o.IsActive;
			oContactDetail.Note = o.Note;
			oContactDetail.DateCreated = o.DateCreated;
			oContactDetail.CreatedBy = o.CreatedBy;
			oContactDetail.DateUpdated = o.DateUpdated;
			oContactDetail.UpdatedBy = o.UpdatedBy;

            return oContactDetail.Update();
        }
		
		/// <summary>
        /// Updates a row in the database table based on the primary key by passing the values of each column as parameters.
        /// </summary>
        /// <returns>Boolean</returns>
		public bool Update(int ContactDetailId, int UserId, int CategoryDetailId, bool IsPrimary, bool IsActive, string Note, DateTime DateCreated, string CreatedBy, DateTime DateUpdated, string UpdatedBy)
        {
            PlacementManager.DAL.ContactDetail_DAL oContactDetail = new PlacementManager.DAL.ContactDetail_DAL();

			oContactDetail.ContactDetailId = ContactDetailId;
			oContactDetail.UserId = UserId;
			oContactDetail.CategoryDetailId = CategoryDetailId;
			oContactDetail.IsPrimary = IsPrimary;
			oContactDetail.IsActive = IsActive;
			oContactDetail.Note = Note;
			oContactDetail.DateCreated = DateCreated;
			oContactDetail.CreatedBy = CreatedBy;
			oContactDetail.DateUpdated = DateUpdated;
			oContactDetail.UpdatedBy = UpdatedBy;

            return oContactDetail.Update();
        }
		
		/// <summary>
        /// Deletes one row in the database table.
        /// </summary>
        /// <param name="o">An object of a datatype representing a row in the database table.</param>
        /// <returns>Boolean</returns>
		public bool Delete(ContactDetail o)
        {
            PlacementManager.DAL.ContactDetail_DAL oContactDetail_DAL = new PlacementManager.DAL.ContactDetail_DAL();
            oContactDetail_DAL.ContactDetailId = o.ContactDetailId;
            return oContactDetail_DAL.Delete();
        }
		
		/// <summary>
        /// Deletes one row in the database table by passing the primary key.
        /// </summary>
        /// <returns>Boolean</returns>
		public bool Delete(int ContactDetailId)
        {
            PlacementManager.DAL.ContactDetail_DAL oContactDetail_DAL = new PlacementManager.DAL.ContactDetail_DAL();
            oContactDetail_DAL.ContactDetailId = ContactDetailId;
            return oContactDetail_DAL.Delete();
        }
		
		/// <summary>
		/// Deletes all rows in a table based on a foreign key.
		/// </summary>
		/// <returns>Boolean</returns>

	}
	
	public class ContactDetailComparer : IComparer<ContactDetail>
    {
        private string _sortColumn;
        private bool _reverse;

        public ContactDetailComparer(string sortExpression)
        {
            _reverse = sortExpression.ToLowerInvariant().EndsWith(" desc");
            if (_reverse)
            {
                _sortColumn = sortExpression.Substring(0, sortExpression.Length - 5);
            }
            else
            {
                _sortColumn = sortExpression;
            }
        }

        public int Compare(ContactDetail a, ContactDetail b)
        {
            int retVal = 0;
            switch (_sortColumn)
            {
				case "ContactDetailId":
					retVal = String.Compare(a.ContactDetailId.ToString(), b.ContactDetailId.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "UserId":
					retVal = String.Compare(a.UserId.ToString(), b.UserId.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "CategoryDetailId":
					retVal = String.Compare(a.CategoryDetailId.ToString(), b.CategoryDetailId.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "IsPrimary":
					retVal = String.Compare(a.IsPrimary.ToString(), b.IsPrimary.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "IsActive":
					retVal = String.Compare(a.IsActive.ToString(), b.IsActive.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "Note":
					retVal = String.Compare(a.Note.ToString(), b.Note.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "DateCreated":
					retVal = String.Compare(a.DateCreated.ToString(), b.DateCreated.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "CreatedBy":
					retVal = String.Compare(a.CreatedBy.ToString(), b.CreatedBy.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "DateUpdated":
					retVal = String.Compare(a.DateUpdated.ToString(), b.DateUpdated.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "UpdatedBy":
					retVal = String.Compare(a.UpdatedBy.ToString(), b.UpdatedBy.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;

            }
            return (retVal * (_reverse ? -1 : 1));
        }
    }
}
